package com.situ.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mall.mapper.OrderItemMapper;
import com.situ.mall.mapper.OrderMapper;
import com.situ.mall.pojo.Order;
import com.situ.mall.pojo.OrderItem;
import com.situ.mall.pojo.query.OrderQuery;
import com.situ.mall.service.IOrderService;
import com.situ.mall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderItemMapper orderItemMapper;
    @Override
    public PageResult<Order> list(OrderQuery orderQuery) {
        PageHelper.startPage(orderQuery.getPage(), orderQuery.getLimit());
        List<Order> orders = orderMapper.selectList(orderQuery);
        PageInfo<Order> pageInfo = new PageInfo<>(orders);
        int count =(int) pageInfo.getTotal();
        return new PageResult<>(0,"",count,orders);
    }

    @Override
    public void deleteById(Long orderNo) {
        orderMapper.deleteByPrimaryKey(orderNo);
    }

    @Override
    public void deleteAll(Long[] ids) {
        orderMapper.deleteAll(ids);
    }

    @Override
    public void add(Order order) {
        orderMapper.insertSelective(order);
    }

    @Override
    public List<OrderItem> selectByOrderNo(Long orderNo) {
        return orderItemMapper.selectByOrderNo(orderNo);
    }

    @Override
    public void changeStatus(Long orderNo,Integer status) {
        orderMapper.changeStatus(orderNo,status);
    }
}
